package com.migration.model.migration.scripts;

import com.migration.model.migration.AbstractMigrationScript;

/**
 * 设备-去往何处(即下一个设备)数据迁移表(risk_device_next_device)迁移脚本
 */
public class A010_RiskDeviceNextDeviceMigrationScript extends AbstractMigrationScript {

    /**
     * 构造函数，初始化迁移配置
     */
    public A010_RiskDeviceNextDeviceMigrationScript() {
        super(
            "risk_device_next_device",
            "设备-去往何处(即下一个设备)数据迁移",
            "ra_node_relation",
            "risk_device_next_device",
            10
        );
    }

    /**
     * 生成迁移数据的SQL
     *
     * @return 迁移数据的SQL
     */
    @Override
    protected String generateMigrationSql() {
        return "INSERT INTO risk_device_next_device (\n" +
               "  id,\n" +
               "  device_id,\n" +
               "  next_device_id\n" +
               ")\n" +
               "SELECT\n" +
               "  nr.id,\n" +
               "  nr.node_id AS device_id,\n" +
               "  nr.linked_id AS next_device_id\n" +
               "FROM risk_lunnan_test.ra_node_relation nr where nr.linked_type = 3;";
    }

    /**
     * 获取源数据SQL
     *
     * @return 源数据查询SQL
     */
    public String getSourceSql() {
        return "SELECT\n" +
               "  nr.id,\n" +
               "  nr.node_id,\n" +
               "  nr.linked_id\n" +
               "FROM risk_lunnan_test.ra_node_relation nr where nr.linked_type = 3;";
    }

    /**
     * 获取目标数据SQL模板
     *
     * @return 目标数据SQL模板
     */
    public String getTargetSqlTemplate() {
        return "INSERT INTO risk_device_next_device (\n" +
               "  id,\n" +
               "  device_id,\n" +
               "  next_device_id\n" +
               ")";
    }
}
